home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / text / misc / ascii2jascii.lha / Ascii2J / Ascii2j.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-20  |  14.6 KB  |  295 lines

  1. /*
  2.  
  3.  Ascii 2 JAscii
  4.  
  5.  Converts standard international ASCII text into Japanese ASCII,
  6.  currently supported are JIS, NewJIS, NEC, EUC and Shift-JIS formats.
  7.  
  8.  by Fabrizio Bartoloni <lanch@caribusiness.it>
  9.  
  10.  This source code is freely distributable but I retain the copyright
  11.  on it, you cannot spread modified versions of this source code without
  12.  my permission.
  13.  
  14.  Write me for suggestions, bug reports, improvements, etc.
  15.  
  16.  !BIG! Thanks to: Emiliano "Skywalk3r" Esposito
  17.                   Alessandro "Crusher" Gatti
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. #define pond "#"
  25.  
  26. static char verstr[] = "$VER: Ascii2Jascii 1.1k (20.10.00)";
  27.  
  28. void usage(void)
  29.  
  30. {
  31. fprintf(stderr,"\n Where infile is the input file to be converted,\n");
  32. fprintf(stderr," the destination file will have the same \n");
  33. fprintf(stderr," name but proper extension according to\n");
  34. fprintf(stderr," the chosen format [.jis|.njis|.nec|.euc|.sjis].\n\n");
  35. }
  36.  
  37. int main (int argc, char **argv)
  38.  
  39. {
  40. char *progname = argv[0];
  41. char buf[256];
  42. char *destfile = argv[2];
  43. FILE *fi,*fp;
  44. char *infile = argv[1];
  45. char *ins = buf;
  46. int size;
  47. int loop;
  48.  
  49. if (argc != 4)
  50.  
  51.  {
  52.  fprintf(stderr,"\n Ascii2Jascii ©2000 by Fabrizio 'Lanch' Bartoloni\n");
  53.  fprintf(stderr,"\n lanch@caribusiness.it\t lanch@tiscalinet.it\n");
  54.  fprintf(stderr,"\n Usage: %s infile outfile [JIS|NJIS|NEC|EUC|SJIS]\n",progname);
  55.  usage();
  56.  exit(1);
  57.  }
  58.  
  59. if (fi = fopen(infile,"r")) {
  60.  
  61. struct tipoheader {
  62. char *ID;        /* Encoding type */
  63. char *header;    /* This header identify the file    */
  64. char *prefix;    /* Prefix for each JAscii character */
  65. char *EndSeq;    /* EOF */
  66. char *space;     /* how empty spaces are represented */
  67. char *punct1, *punct2, *punct3, *punct4, *punct5, *punct6;
  68. char *punct7, *punct8, *punct9, *punct10, *punct11, *punct12;
  69. char *punct13, *punct14, *punct15, *punct16, *punct17, *punct18, *punct19;
  70. char *punct20, *punct21, *punct22, *punct23, *punct24, *punct25, *punct26;
  71. char *number1, *number2, *number3, *number4, *number5;
  72. char *number6, *number7, *number8, *number9, *number0;
  73. int alfa;        /* how much the JAscii will be shifted from ASCII */
  74.                   };
  75.  
  76. struct tipoheader codes[] =
  77.  {
  78.  "JIS", "$@", pond, "(J\n", "!!", "!%", "!'", "!(", "!)", "!*", "!@",
  79.   "!A", "!K", "!J", "!N", "!O", "!Q", "!P", "!S", "!R", "!\\", "!]",
  80.   "!a", "!p", "!r", "!s", "!t", "!u", "!v", "!w", "!x", "#1", "#2",
  81.   "#3", "#4", "#5", "#6", "#7", "#8", "#9", "#0", 0,
  82.  "NJIS", "$B", "#", "(J\n", "!!", "!%", "!'", "!(", "!)", "!*", "!@",
  83.   "!A", "!K", "!J", "!N", "!O", "!Q", "!P", "!S", "!R", "!\\", "!]",
  84.   "!a", "!p", "!r", "!s", "!t", "!u", "!v", "!w", "!x", "#1", "#2",
  85.   "#3", "#4", "#5", "#6", "#7", "#8", "#9", "#0", 0,
  86.  "SJIS", "", "‚", "", "@", "D", "F", "G", "H", "I", "_", "`",
  87.   "j", "i", "m", "n", "p", "o", "r", "q", "{", "|", "m",
  88.   "", "’", "“", "”", "•", "–", "—", "˜", "‚P", "‚Q", "‚R",
  89.   "‚S", "‚T", "‚U", "‚V", "‚W", "‚X","‚Z", 32,
  90.  "NEC", "K", pond, "H", "!!", "!%", "!'", "!(", "!)", "!*", "!@",
  91.   "!A", "!K", "!J", "!N", "!O", "!Q", "!P", "!S", "!R", "!\\", "!]",
  92.   "!a", "!p", "!r", "!s", "!t", "!u", "!v", "!w", "!x", "#1", "#2",
  93.   "#3", "#4", "#5", "#6", "#7", "#8", "#9", "#0", 0,
  94.  "EUC", "", "£", "", "¡¡", "¡¥", "¡§", "¡\"", "¡©", "¡ª", "¡À",
  95.   "¡Á", "¡Ë", "¡Ê", "¡Î", "¡Ï", "¡Ñ", "¡Ð", "¡Ó", "¡Ò", "¡Ü",
  96.   "¡Ý", "¡á", "¡ð", "¡ò", "¡ó", "¡ô", "¡õ", "¡ö", "¡÷", "¡ø", "£±",
  97.   "£²", "£³", "£´", "£µ", "£¶", "£·", "£¸", "£¹", "£°", 128
  98.  };
  99.  
  100. int x; /* position inside the structure */
  101.  
  102. if ((strcmp(argv[3], "JIS")) == 0)
  103.                   {
  104.                   x = 0;
  105.                   }
  106. else if ((strcmp(argv[3], "NJIS")) == 0)
  107.                   {
  108.                   x = 1;
  109.                   }
  110. else if ((strcmp(argv[3], "SJIS")) == 0)
  111.                   {
  112.                   x = 2;
  113.                   }
  114. else if ((strcmp(argv[3], "NEC")) == 0)
  115.                   {
  116.                   x = 3;
  117.                   }
  118. else if ((strcmp(argv[3], "EUC")) == 0)
  119.                   {
  120.                   x = 4;
  121.                   }
  122.  
  123. else                  {
  124.                       fprintf(stderr," Required format is either unknown or unavailable\n");
  125.                       exit(1);
  126.                       }
  127.  
  128.  if (fp = fopen(destfile,"w")) {
  129.  
  130.                                 while (fgets(buf,sizeof(buf), fi)) {
  131.                                 fprintf(fp,"%s",codes[x].header);
  132.                                 size = strlen(buf);
  133.  
  134.                                    for (loop = 0;loop < size; loop++)
  135.  
  136.                                        {
  137.  
  138.                                         switch (ins[loop])
  139.                                                           
  140.                                                           {
  141.                                                           case ' ' :
  142.                                                           fprintf(fp,"%s", codes[x].space);
  143.                                                                       break;
  144.                                                           case '1' :
  145.                                                           fprintf(fp,"%s", codes[x].number1);
  146.                                                                       break;
  147.                                                           case '2' :
  148.                                                           fprintf(fp,"%s", codes[x].number2);
  149.                                                                       break;
  150.                                                           case '3' :
  151.                                                           fprintf(fp,"%s", codes[x].number3);
  152.                                                                       break;
  153.                                                           case '4' :
  154.                                                           fprintf(fp,"%s", codes[x].number4);
  155.                                                                       break;
  156.                                                           case '5' :
  157.                                                           fprintf(fp,"%s", codes[x].number5);
  158.                                                                       break;
  159.                                                           case '6' :
  160.                                                           fprintf(fp,"%s", codes[x].number6);
  161.                                                                       break;
  162.                                                           case '7' :
  163.                                                           fprintf(fp,"%s", codes[x].number7);
  164.                                                                       break;
  165.                                                           case '8' :
  166.                                                           fprintf(fp,"%s", codes[x].number8);
  167.                                                                       break;
  168.                                                           case '9' :
  169.                                                           fprintf(fp,"%s", codes[x].number9);
  170.                                                                       break;
  171.                                                           case '0' :
  172.                                                           fprintf(fp,"%s", codes[x].number0);
  173.                                                                       break;
  174.                                                           case '.' :
  175.                                                           fprintf(fp,"%s", codes[x].punct1);
  176.                                                                       break;
  177.                                                           case ':' :
  178.                                                           fprintf(fp,"%s", codes[x].punct2);
  179.                                                                       break;
  180.                                                           case ';' :
  181.                                                           fprintf(fp,"%s", codes[x].punct3);
  182.                                                                       break;
  183.                                                           case '?' :
  184.                                                           fprintf(fp,"%s", codes[x].punct4);
  185.                                                                       break;
  186.                                                           case '!' :
  187.                                                           fprintf(fp,"%s", codes[x].punct5);
  188.                                                                       break;
  189.                                                           case '\'' :
  190.                                                           fprintf(fp,"%s", codes[x].punct6);
  191.                                                                       break;
  192.                                                           case '~' :
  193.                                                           fprintf(fp,"%s", codes[x].punct7);
  194.                                                                       break;
  195.                                                           case ')' :
  196.                                                           fprintf(fp,"%s", codes[x].punct8);
  197.                                                                       break;
  198.                                                           case '(' :
  199.                                                           fprintf(fp,"%s", codes[x].punct9);
  200.                                                                       break;
  201.                                                           case '[' :
  202.                                                           fprintf(fp,"%s", codes[x].punct10);
  203.                                                                       break;
  204.                                                           case ']' :
  205.                                                           fprintf(fp,"%s", codes[x].punct11);
  206.                                                                       break;
  207.                                                           case '}' :
  208.                                                           fprintf(fp,"%s", codes[x].punct12);
  209.                                                                       break;
  210.                                                           case '{' :
  211.                                                           fprintf(fp,"%s", codes[x].punct13);
  212.                                                                       break;
  213.                                                           case '>' :
  214.                                                           fprintf(fp,"%s", codes[x].punct14);
  215.                                                                       break;
  216.  
  217.                                                           case '<' :
  218.                                                           fprintf(fp,"%s", codes[x].punct15);
  219.                                                                       break;
  220.  
  221.                                                           case '+' :
  222.                                                           fprintf(fp,"%s", codes[x].punct16);
  223.                                                                       break;
  224.  
  225.                                                           case '-' :
  226.                                                           fprintf(fp,"%s", codes[x].punct17);
  227.                                                                       break;
  228.  
  229.                                                           case '=' :
  230.                                                           fprintf(fp,"%s", codes[x].punct18);
  231.                                                                       break;
  232.                                                           case '$' :
  233.                                                           fprintf(fp,"%s", codes[x].punct19);
  234.                                                                       break;
  235.                                                           case '£' :
  236.                                                           fprintf(fp,"%s", codes[x].punct20);
  237.                                                                       break;
  238.                                                           case '%' :
  239.                                                           fprintf(fp,"%s", codes[x].punct21);
  240.                                                                       break;
  241.                                                           case '#' :
  242.                                                           fprintf(fp,"%s", codes[x].punct22);
  243.                                                                       break;
  244.  
  245.                                                           case '&' :
  246.                                                           fprintf(fp,"%s", codes[x].punct23);
  247.                                                                       break;
  248.  
  249.                                                           case '*' :
  250.                                                           fprintf(fp,"%s", codes[x].punct24);
  251.                                                                       break;
  252.  
  253.                                                           case '@' :
  254.                                                           fprintf(fp,"%s", codes[x].punct25);
  255.                                                                       break;
  256.  
  257.                                                           case '§' :
  258.                                                           fprintf(fp,"%s", codes[x].punct26);
  259.                                                                       break;
  260.  
  261.                                                           case '\n' :
  262.                                                           fprintf(fp,"%s", codes[x].EndSeq);
  263.                                                                       break;
  264.  
  265.                                                           default :
  266.                                                           fprintf(fp,"%s%c",codes[x].prefix,ins[loop] + codes[x].alfa);
  267.                                                                     break;
  268.                                                           } /* endswitch */
  269.                                        } /* endloop */
  270.  
  271.                                                                    } /* endwhile */
  272.  
  273.                                } /* endif outfile   */
  274.  
  275.                                else {
  276.                                     fprintf(stderr,"unable to create output file: %s\n", destfile);
  277.                                     exit(1);
  278.                                     }
  279.  
  280.  
  281.                             } /* endif open file */
  282.  
  283.                             else {
  284.                                   fprintf(stderr,"unable to open file: %s!\n",argv[1]);
  285.                                   exit(1);
  286.                                  }
  287.  
  288. fclose(fp);
  289. fclose(fi);
  290.  
  291. puts("\n Conversion Done!\n");
  292. return(0);
  293. }
  294.  
  295.